using System;
using System.Configuration;
using System.Web.UI;
using System.Resources;
using HelpdeskServices.Properties;

public partial class LaunchWorkflow2 : Page
{
    private string entityId;
    private string entityName;


    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.Request.QueryString.HasKeys())
        {
            ReadQueryStringParameters();
            if (entityId != null)
            {
                ExecuteWorkFlow();
            }
        }
    }

    /// <summary>
    /// Executes the work flow.
    /// </summary>
    private void ExecuteWorkFlow()
    {
        WorkFlow workflow = new WorkFlow();

        try
        {
            workflow.LaunchWorkFlow(entityId, entityName, ConfigurationManager.AppSettings[Resources.ConfigurationKeyForWorkFlow2Id]);
            FeedbackMessageLabel.Text = UserFeedback.ErrorWhileExecutingWorkflow;
        }
        catch (Exception error)
        {
            Common.LogErrorMessage(error);
            Response.Write(error.Message);
        }
    }

    /// <summary>
    /// Reads the query string parameters.
    /// </summary>
    private void ReadQueryStringParameters()
    {
        entityName = Page.Request.QueryString[Resources.QueryStringParameterObjectType];
        entityId = Page.Request.QueryString[Resources.QueryStringParameterId];
    }
}